#pragma once

#include "Object.h"
#include "../OpenGL.h"

class Point3D;

class Light : public Object
{
private:
    int lightNum;//-1 if no light
	float attenuationConstant;
	float attenuationLinear;
	float attenuationQuadratic;
    
    GLenum getLightEnum();
    bool requestControl();
    
public:
    static GLenum getLightEnum(int num);
    
    class LightSettings
    {
    private:
        bool use;
        float intensity,r,g,b;
    public:
        LightSettings();
        ~LightSettings();
        
        float getRed();
        float getGreen();
        float getBlue();
        float getIntensity();
        LightSettings& setIntensity(float intensity);
        LightSettings& setColor(int hexColor);
        LightSettings& setColor(float r, float g, float b);
        LightSettings& disable();
        LightSettings& enable();
        
        void drawMe(GLenum lightEnum,GLenum lightType);//only call from Light()
    }ambient,diffuse;
	class LightSettingsSpecular : public LightSettings
	{
	private:
		float cutoff;
		int exponent;
	public:
		LightSettingsSpecular();
		~LightSettingsSpecular();
		double getCuffoff();
		int getExponent();
		LightSettingsSpecular& setCutoff(double cutoff);
		LightSettingsSpecular& setExponent(int exponent);
		void drawSpec(GLenum lightEnum,GLenum lightType);//only call from Light()
	}specular;
    
    Light();
    ~Light();
	
	double getAttenuationConstant();
	double getAttenuationLinear();
	double getAttenuationQuadratic();
	Light& setAttenuationConstant(double value);
	Light& setAttenuationLinear(double value);
	Light& setAttenuationQuadratic(double value);
    
    bool hasLightControl();
    void draw();
};

class LightStudio
{
private:
    Light *inUse[8];//array of pointers
    int ambientLight;
    
public:
    LightStudio();
    ~LightStudio();
    
    int requestLightControl(Light *light);//should only be called from Light
    bool releaseLightControl(Light *light);//should only be called from Light
    
    LightStudio& setGlobalAmbientLight(int hexColor);
    int getGlobalAmbientLight();
};

extern LightStudio lightStudio;
